package com.wfit.bankproject.service;


import com.wfit.bankproject.entity.User;
import com.wfit.bankproject.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class AuthorizeService implements UserDetailsService {
    @Autowired
    private UserMapper usersMapper;
    @Autowired
    private UserRoleService userRoleService;
    @Override
    public LoginUser loadUserByUsername(String username) throws UsernameNotFoundException {
        User account = usersMapper.findUsersByName(username);

        if(Objects.isNull(account)){
            throw new UsernameNotFoundException("没有该用户");
        }

//        return User.withUsername(account.getUsername()).password(account.getPassword()).roles("admin").build();
        String[] authority= {"ROLE_USER"};
        return new LoginUser(account,authority);
    }
}
